<?php
/**
 * 评论接口
 * @author goss
 */
class comment extends MY_Api {
	
	public function __construct(){
		if ( !get_uid() ){
			redirect('user/login');
		}
		$this->load->model('Comment_model','comment');
	}
	
	public function add($type='newsfeed'){
		$this->load->library('form_validation');
		$this->form_validation->set_rules('content', 'lang:content', 'required|xss_clean');
		if ( $this->form_validation->run() !== FALSE ){
			$content = $this->input->post('content');
			$contentid = $this->input->post('contentid');
			$fileid  = $this->input->post('fileid');
			$data = array(
					'content'=>$content,
					'fileid'=>$fileid?$fileid:0,
					'uid'=>get_uid()
			);
			$status = $this->comment->insert($data);
			if (!$status){
				$this->set_msg($this->lang->line('sys_error'));
				$this->set_error_code(600);
				$this->output();
			}
			$this->load->model('file_model','file');
			$file_info = $this->file->get($fileid);
			$data['file'] = $file_info;
			$this->set_data($data);
			$this->set_msg($this->lang->line('oprate_success'));
			$this->output();
		}
	}
	
	public function delete($cid){
		$status = $this->comment->delete($cid);
		if ($status){
			$this->set_msg($this->lang->line('oprate_success'));
		}
		else{
			$this->set_error_code(601);
			$this->set_msg('');
		}
		$this->output();
	}
	
	
}